<template>
  <div>
    <h2>我是主页</h2>
    <p>我是主页内容</p>
    <p>{{message}}</p>

    <router-link to="/home/news">新闻</router-link>
    <router-link to="/home/message">消息</router-link>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'home',
  data() {
    return {
      message: "I'm don't see you",
      path: '/home/news'
    }
  },
  // 创建时调用一次
  created() {
    console.log('home created')
    // 修改标题
    document.title = "首页"
    // this.$router.push('/home/news')
    
  },
  // 销毁时调用(生命周期结束)
  destroyed () {
    console.log("home destroyed")
  },
  // 组件挂载完成时调用一次
  mounted() {
    console.log('home mounted')
  },
  // 刷新时回调
  updated() {
    console.log('updated')
  },

  // activated与deactivated只有使用keep-alive时才可以使用
  // 页面活跃状态掉调用
  activated () {
    console.log('activated', this.path)
    this.$router.push(this.path)
  },
  // 页面不活跃状态调用
  deactivated () {
    console.log('deactivated')
  },



  // 离开时记录路由: 可以访问组件实例
  beforeRouteLeave (to, from, next) {
    this.path = from.path
    console.log(this.path)
    next()
  }
}
</script>

<style>

</style>